<meta args="params"/>
<form class="form-horizontal" id="form" s="form,datac,nda,valid" s-data="params">
    <table class="table table-bordered table-condensed">
        <tr>
            <th><code>title</code></th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm" name="title" />
                <div class="help-block">页面标题</div>
            </td>
            <th><code>返回Title</code></th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm" name="leftTitle" />
            </td>
        </tr>
        <tr>
            <th>关键字</th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm" name="keywords" />
            </td>
            <th>显示分类</th>
            <td>
                <label class="s-checkbox">
                    <input autocomplete="off" type="checkbox" name="showShopcat" value="true">
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
        </tr>
        <tr>
            <th>搜索类型</th>
            <td>
                <select class="form-control ecomPlat input-sm" s="select"
                        name="searchFrom"
                        s-build="S.get('/api/enum/valuesMap/core.enums.SearchFrom')">
                    <option value="">搜索类型</option>
                </select>
            </td>
            <th>淘宝物料分类</th>
            <td>
                <select class="form-control" s="select"
                        id="taobaoMaterialCat"
                        name="taobaoMaterialCatId"
                        s-build="S.get('/api/taobao-material-cat/list')">
                    <option value="">物料类目</option>
                </select>
                <select class="form-control" s="select"
                        name="taobaoMaterialId"
                        s-datac-ng="true"
                        s-data="params"
                        s-build-switch="'off-on'"
                        s-select="{value: 'materialId'}"
                        id="taobaoMaterial"
                        s-build="S.get('/api/taobao-material-cat/material/list/' + ($taobaoMaterialCat.val() || 0))">
                    <option value="">淘宝物料</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>最低价</th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm"
                       s-valid-error="require(false),number()" name="startPrice" />
            </td>
            <th>最高价</th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm"
                       s-valid-error="require(false),number()" name="endPrice"/>
            </td>
        </tr>
        <tr>
            <th>排序</th>
            <td>
                <select class="form-control ecomPlat input-sm" s="select"
                        name="sort"
                        s-build="S.get('/api/enum/valuesMap/core.enums.CommissionItemSort')">
                    <option value="">选择排序</option>
                </select>
            </td>
            <th>电商平台</th>
            <td>
                <select class="form-control ecomPlat input-sm" s="select"
                        name="ecomPlat"
                        s-build="S.get('/api/enum/valuesMap/core.enums.EcomPlat')">
                    <option value="">选择电商平台</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>频道ids</th>
            <td>
                <select class="form-control input-sm" s="select" s-build="S.get('/api/channel/list')" name="channelIds">
                    <option value="">不选频道</option>
                </select>
            </td>
            <th>分类ids</th>
            <td>
                <input autocomplete="off" type="text" class="form-control input-sm" name="catIds" id="catIds" s-dbclick="selectShopcat()"/>
                <div class="help-block">分类id，多个用逗号隔开，如catIds=3,4</div>
            </td>
        </tr>
        <tr>
            <th>是否推荐</th>
            <td>
                <label class="s-checkbox">
                    <input autocomplete="off" type="checkbox" name="recommend" value="true">
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
            <th>包邮</th>
            <td>
                <label class="s-checkbox">
                    <input autocomplete="off" type="checkbox" name="freeShipment" value="true">
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
        </tr>
        <tr>
            <th>最低销量</th>
            <td>
                <input autocomplete="off" type="number" class="form-control input-sm" name="minSales" />
            </td>
            <th>优惠券</th>
            <td>
                <label class="s-checkbox">
                    <input autocomplete="off" type="checkbox" name="coupon" value="true">
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
        </tr>
        <tr>
            <th>广告位</th>
            <td colspan="3">
                <select name="advSpaceId" class="form-control" s="select" s-build="S.get('/api/adv-space/list')">
                    <option value="">选择广告位</option>
                </select>
            </td>
        </tr>
    </table>
</form>
<script>
    S.getParams = function() {
        var deferred = $.Deferred();
        $form.validate().done(function() {
            deferred.resolve($form.node.serialize());
        })
        return deferred;
    }
    function selectShopcat() {
        S.popupOpen("/shopcat/shopcatSelector.html", {multi: true}).done(function(shopcats, path) {
            if(shopcats && shopcats.length) {
                var ids = $catIds.node.val();
                if(ids != '') {
                    ids += ","
                }
                ids += shopcats.map(function(s) { return s.id}).join(",")
                $catIds.node.val(ids)
            }
        })
    }

    S.on('s-ready', function(){
      S.cascade($taobaoMaterialCat, $taobaoMaterial);
    })
</script>